package com.patrol.logisticsmanage.net;

import com.google.gson.Gson;
import com.tencent.mmkv.MMKV;


public class AppConfig {

    public static void putObject(String key, Object value){
        kv.putString(key,new Gson().toJson(value));
    }

    public static <T> T getObject(String key, Class<T> value){
        return new Gson().fromJson(getString(key,null),value);
    }

    public static void clear(){
       kv.clearAll();
    }

    /*public static boolean saveStringArray(List<String> sKey) {
        SharedPreferences.Editor edit=mSharedPreferences.edit();
        edit.putInt("Status_size",sKey.size()); *//*sKey is an array*//*
        for(int i=0;i<sKey.size();i++) {
            edit.remove("Status_" + i);
            edit.putString("Status_" + i, sKey.get(i));
        }
        return edit.commit();
    }*/

   /* public static List<String> loadArray(Context mContext) {
        List<String> sKey = new ArrayList<>();
        sKey.clear();
        int size = getInt("Status_size");
        for(int i=0;i<size;i++) {
            sKey.add(getString("Status_" + i, null));
        }
        return sKey;
    }*/

    private static MMKV kv = MMKV.defaultMMKV();

    public static void putString(String key,String value){
        kv.putString(key,value);
    }

    public static void putBoolean(String key,boolean value){
        kv.putBoolean(key,value);
    }

    public static void putInt(String key,int value){
        kv.putInt(key,value);
    }

    public static String getString(String key,String value){
        return kv.getString(key,value);
    }
    public static String getString(String key){
        return kv.getString(key,null);
    }

    public static boolean getBoolean(String key,boolean value){
        return kv.getBoolean(key,value);
    }

    public static boolean getBoolean(String key){
        return kv.getBoolean(key,false);
    }

    public static int getInt(String key,int value){
        return kv.getInt(key,value);
    }

    public static int getInt(String key){
        return kv.getInt(key,0);
    }
}
